package locale;


import org.jdom.*;
import javax.faces.context.FacesContext;
import java.util.Locale;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

import com.UtilsPak.localization.*;

public  class LocaleConf {


    private String langCd;
    private static Locale locale;

    public String getLangCd() {
        if(langCd==null)
            langCd="uk";
        return langCd;
    }

    public void setLangCd(String langCd) {
        this.langCd = langCd;
    }

    public String changeLocale(){
        FacesContext ctx = FacesContext.getCurrentInstance() ;
        ctx.getViewRoot().setLocale(new Locale(getLangCd()));
        locale = new Locale(getLangCd());
        return null;
    }


    public static String getLocalized(String constant) {
        String retVal = "";

        if (constant != null && !constant.equals("")) {
            LocalizationManager.setFc(FacesContext.getCurrentInstance());
            retVal = LocalizationManager.getLocalized(constant,getLocale());
        }
        return retVal;
    }


    /**
     * Method returns Locale correspond to current user language.
     *
     * @return
     */
    public static String getLocale() {
        Locale retVal;
        if (locale==null ){
            retVal = FacesContext.getCurrentInstance().getViewRoot().getLocale();
            locale = retVal;
        }
        else
        {
            retVal= locale;
        }

        return retVal.getLanguage();
    }

}
